<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ include file="../../base.jsp"%>
<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>数据 - AdminLTE2定制版</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 页面meta /-->
    <script src="${ctx}/plugins/jQuery/jquery-2.2.3.min.js"></script>
</head>


<script>
    
    function goToFinance() {
        
        //判断是否有选中checkbox
        let butts = $(`input[type="checkbox"]:checked`);
        console.log(butts);
        if(butts==null || butts.length==0){
            alert("请选择要要生成财务报运单的发票！")
            return;
        }
        if(butts.length > 1){
            alert("只能选择一个发票！")
            return;
        }
        
        let id = butts.val();
        let url = "/cargo/finance/toAdd";
        window.location.href = url+"?id="+id;
        
    }

    
    function deleteById() {

        //判断是否有选中checkbox
        let butts = $(`input[type="checkbox"]:checked`);

        if(butts==null || butts.length==0){
            alert("请选择要删除的发票！")
            return;
        }
        if(butts.length > 1){
            alert("只能选择一个要删除的发票！")
            return;
        }

        if(confirm("确定要删除该发票吗?")){
            //动态获取id
            let id = butts.val();
            $.ajax({
                url:"/cargo/invoice/delete",
                type:"get",
                data:{
                    id:id
                },
                success:function (result) {
                    if(result.status){
                        alert(result.message);
                        window.location.href = "/cargo/invoice/list.do"
                    }else{
                        alert(result.message);
                    }
                }
            });
        }
    }

    
    function view() {
        //判断是否有选中checkbox
        let butts = $(`input[type="checkbox"]:checked`);
        console.log(butts);
        if(butts==null || butts.length==0){
            alert("请选择要查看的发票！")
            return;
        }
        if(butts.length > 1){
            alert("只能选择一个查看的发票！")
            return;
        }

        //动态获取id
        let id = butts.val();
        let url = "/cargo/invoice/toView";
        window.location.href = url+"?invoiceId="+id;
    }

    function exportAsExcel(){


        //判断是否有选中checkbox
        let butts = $(`input[type="checkbox"]:checked`);
        console.log(butts);
        if(butts==null || butts.length==0){
            alert("请选择要导出的发票！")
            return;
        }
        if(butts.length > 1){
            alert("只能选择一个发票！")
            return;
        }

        //动态获取id
        let id = butts.val();
        let url = "/cargo/invoice/toExcel.do";
        window.location.href = url+"?invoiceId="+id;
        
    }
    
    
    
    
    
</script>
<body>
<div id="frameContent" class="content-wrapper" style="margin-left:0px;">
    
    <section class="content-header">
        <h1>
            货运管理
            <small>发票管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="all-admin-index.html"><i class="fa fa-dashboard"></i> 首页</a></li>
        </ol>
        
    </section>
    <!-- 内容头部 /-->
    
    <!-- 正文区域 -->
    <section class="content">
        
        <!-- .box-body -->
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">发票列表</h3>
            </div>
            
            <div class="box-body">
                
                <!-- 数据表格 -->
                <div class="table-box">
                    
                    <!--工具栏-->
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default" title="查看" onclick='view()'><i class="fa  fa-eye-slash"></i> 查看</button>
                                <button type="button" class="btn btn-default" title="删除" onclick='deleteById()'><i class="fa fa-print"></i> 删除</button>
                                <button type="button" class="btn btn-default" title="导出Eexcel" onclick='exportAsExcel()'><i class="fa fa-print"></i> 导出Eexcel</button>
                                <button type="button" class="btn btn-default" title="财务报运单" onclick="goToFinance()"><i class="fa fa-refresh"></i> 财务报运单</button>
                            </div>
                        </div>
                    </div>
                    
                    <div class="box-tools pull-right">
                        <div class="has-feedback">
                            <input type="text" class="form-control input-sm" placeholder="搜索">
                            <span class="glyphicon glyphicon-search form-control-feedback"></span>
                        </div>
                    </div>
                    <!--工具栏/-->
                    
                    <!--数据列表-->
                    <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                        <thead>
                        <tr>
                            <th class="" style="padding-right:0px;"><input type="checkbox" name="selectAll"/></th>
                            <th class="sorting">发票编号</th>
                            <th class="sorting">报运合同号</th>
                            <th class="sorting">贸条款</th>
                            <th class="sorting">发票金额</th>
                            <th class="sorting">发票时间</th>
                            <th class="sorting">发票状态</th>
                        </tr>
                        </thead>
                        
                        <tbody>
                        
                        <form id="exportForm" action="/cargo/finance/toAdd.do" method="post">
                            <input type="hidden" name="id" id="invoiceId">
                            
                            <c:forEach items="${pageInfo.list}" var="o" varStatus="status">
                                <tr>
                                    <td><input type="checkbox" name="id" value="${o.invoiceId}"/></td>
                                    <td>${o.invoiceId}</td>
                                    <td>${o.scNo}</td>
                                    <td>${o.tradeTerms}</td>
                                    <td>${o.invoiceMoney}</td>
                                    <td>${o.invoiceTime}</td>
                                    <td>${o.state == 0 ? '草稿' : '已生成财务报表'}</td>
                                </tr>
                                
                            </c:forEach>
                            
                        </form>
                        </tbody>
                    </table>
                </div>
            </div>
            <!-- /.box-body -->
            
            <!-- .box-footer-->
            <div class="box-footer">
                <jsp:include page="../../common/page.jsp">
                    <jsp:param value="/cargo/invoice/list.do" name="pageUrl"/>
                </jsp:include>
            </div>
            
        </div>
    </section>
</div>
</body>

</html>
